package ceet.sadmin;

import java.sql.ResultSet;
import java.sql.SQLException;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;
import com.sun.org.apache.bcel.internal.generic.IFGT;
import ceet.ac.cn.dao.DbHelper;

public class SadminDao {
		public SadminUser selectSadminid(int sid){  //根据ID进行查询
	        Connection conn = (Connection) DbHelper.getConnection();
	        String sql  = "select * from sadmin where sid = "+sid;
	        SadminUser s = null;
	        try {
	            PreparedStatement pst = (PreparedStatement) conn.prepareStatement(sql);
	            ResultSet rst = pst.executeQuery();
	            while (rst.next()) {
	                s = new SadminUser();
	                s.setSid(rst.getInt("sid"));
	                s.setSname(rst.getString("sname"));
	                s.setSage(rst.getString("sage"));
	                s.setSshool(rst.getString("sschool"));
	                s.setSold(rst.getString("sold"));
	                s.setSten(rst.getString("sten"));
	            }
	            rst.close();
	            pst.close();
	        } catch (SQLException e) {
	            e.printStackTrace();
	        }
	        return s;  //返回
		
	}
	    public Sadmin dologin(int adminid,String pass){ 
				Sadmin u=null;
				try {
					Connection conn = (Connection) DbHelper.getConnection();
					String sql="select * from cadmin where adminid=? and pass=?";
					PreparedStatement pst = (PreparedStatement) conn.prepareStatement(sql);
		            ResultSet rst = pst.executeQuery();
					pst.setInt(1,adminid);
					pst.setString(2,pass);
					rst=pst.executeQuery();
					while(rst.next()){
						u=new Sadmin();
						u.setAdminid(adminid);
						u.setPass(pass);
				}rst.close();
	            pst.close();
	        } catch (SQLException e) {
	            e.printStackTrace();
	        }
				return u;
			}
}
